const TransformPages = require('uni-read-pages')
const { webpack } = new TransformPages()
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin') //最新版本copy-webpack-plugin插件暂不兼容，推荐v5.0.0
module.exports = {
	transpileDependencies: ['@dcloudio/uni-ui', 'uview-ui'],
	configureWebpack: {
		plugins: [
			new webpack.DefinePlugin({
				ROUTES: webpack.DefinePlugin.runtimeValue(() => {
					const tfPages = new TransformPages({
						includes: ['path', 'name', 'aliasPath'],
					})
					return JSON.stringify(tfPages.routes)
				}, true),
			}),
		].concat(
			process.env.UNI_PLATFORM === 'mp-toutiao'
				? [
						new CopyWebpackPlugin({
							patterns: [
								{
									from: path.join(__dirname, 'src/douyin.package.json'),
									to: path.join(
										__dirname,
										'dist',
										process.env.NODE_ENV === 'production' ? 'build' : 'dev',
										process.env.UNI_PLATFORM,
										'package.json'
									),
								},
							],
						}),
				  ]
				: []
		),
	},
}
